package com.hzhr.iot.user.convertor;

import com.hzhr.iot.user.convertor.custom.*;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.core.util.HzhrJsonUtil;
import java.util.Map;
import com.hzhr.iot.user.model.resource.ResourceModel;
import com.hzhr.iot.user.model.resource.ResourcePostModel;
import com.hzhr.iot.user.model.resource.ResourcePutModel;
import com.hzhr.iot.user.entity.ResourceEntity;
import com.hzhr.iot.user.entity.ext.ResourceEntityExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.hzhr.iot.user.model.resource.ResourceModel;
import com.hzhr.iot.user.model.resource.ResourceGetModel;
import com.hzhr.iot.user.model.resource.ResourcePostModel;
import com.hzhr.iot.user.model.resource.ResourcePutModel;
import com.hzhr.iot.user.queryModel.custom.ResourceCustomQueryModel;

@Component
public class ResourceConvertor {
    @Autowired
    ActionCustomConvertor actionCustomConvertor;
    @Autowired
    ActionInRoleCustomConvertor actionInRoleCustomConvertor;
    @Autowired
    CompanyCustomConvertor companyCustomConvertor;
    @Autowired
    DeptCustomConvertor deptCustomConvertor;
    @Autowired
    OptionsCustomConvertor optionsCustomConvertor;
    @Autowired
    ResourceInActionCustomConvertor resourceInActionCustomConvertor;
    @Autowired
    RoleCustomConvertor roleCustomConvertor;
    @Autowired
    UserCustomConvertor userCustomConvertor;
    @Autowired
    UserInRoleCustomConvertor userInRoleCustomConvertor;

    public ResourceEntity resourceModel2entity(ResourceModel in) {
        //未转换字段: createUserId createTime updateUserId isValid updateTime state title 
        if (in == null) return null;
        ResourceEntity result = new ResourceEntity();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setService(HzhrTypeUtil.string2string(in.getService()));
        result.setVersion(HzhrTypeUtil.string2string(in.getVersion()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        return result;
    }
    public ResourceEntity resourceModel2entity(ResourceModel in, ResourceEntity ori) {
        //未转换字段: createUserId createTime updateUserId isValid updateTime state title 
        if (in == null) return null;
        ResourceEntity result = ori;

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setService(HzhrTypeUtil.string2string(in.getService()));
        result.setVersion(HzhrTypeUtil.string2string(in.getVersion()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        return result;
    }
    public List<ResourceEntity> resourceModelList2entityList(List<ResourceModel> in) {
        if (in == null) return null;
        List<ResourceEntity> result = new ArrayList<>();
        for (ResourceModel item : in) {
            result.add(resourceModel2entity(item));
        }
        return result;
    }
    public ResourceModel entity2resourceModel(ResourceEntity in) {
        //未转换字段: userId mask 
        if (in == null) return null;
        ResourceModel result = new ResourceModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setService(HzhrTypeUtil.string2string(in.getService()));
        result.setVersion(HzhrTypeUtil.string2string(in.getVersion()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        return result;
    }
    public List<ResourceModel> entityList2resourceModelList(List<ResourceEntity> in) {
        if (in == null) return null;
        List<ResourceModel> result = new ArrayList<>();
        for (ResourceEntity item : in) {
            result.add(entity2resourceModel(item));
        }
        return result;
    }
    public ResourceModel ext2resourceModel(ResourceEntityExt in) {
        //未转换字段: userId mask 
        if (in == null) return null;
        ResourceModel result = new ResourceModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setService(HzhrTypeUtil.string2string(in.getService()));
        result.setVersion(HzhrTypeUtil.string2string(in.getVersion()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        return result;
    }
    public List<ResourceModel> extList2resourceModelList(List<ResourceEntityExt> in) {
        if (in == null) return null;
        List<ResourceModel> result = new ArrayList<>();
        for (ResourceEntityExt item : in) {
            result.add(ext2resourceModel(item));
        }
        return result;
    }
    public ResourceGetModel extList2resourceGetModel(List<ResourceEntityExt> extList, Integer total, Integer changeCount, Map<String, Object> query) {
        List<ResourceModel> modelList = extList2resourceModelList(extList);
        if (modelList == null) {
            ResourceGetModel result = new ResourceGetModel();
            result.setTotal(total);
            result.setChangeCount(changeCount);
            return result;
        }

         String _show = HzhrTypeUtil.object2string(query.get("_show"));
         Boolean _show_info = query.get("_show_info") != null ? Boolean.parseBoolean(query.get("_show_info").toString()) : false;

        if (!_show_info) {
            for (ResourceModel model : modelList) {
                model.setService(null);
                model.setVersion(null);
                model.setUri(null);
                model.setDes(null);
                model.setMask(null);
                model.setUserId(null);
            }
        }

        ResourceGetModel result = new ResourceGetModel();
        if ("one".equals(_show)) {
            if (modelList.size() > 0) {
                result.setModel(modelList.get(0));
            }
         }
        if ("list".equals(_show)) {
            result.setModelList(modelList);
        }
        result.setTotal(total);
        result.setChangeCount(changeCount);
        return result;
    }
    public ResourceGetModel entity2resourceGetModel(ResourceEntity entity, Integer total, Integer changeCount, Map<String, Object> query) {
        List<ResourceEntityExt> extList = new ArrayList<>();
        if (entity == null) return extList2resourceGetModel(extList, total, changeCount, query);
        extList.add(HzhrJsonUtil.convertObjectType(entity, ResourceEntityExt.class));
        return extList2resourceGetModel(extList, total, changeCount, query);
     }
    public ResourceEntity resourcePostModel2entity(ResourcePostModel in) {
        //未转换字段: createUserId createTime updateUserId isValid updateTime id state title 
        if (in == null) return null;
        ResourceEntity result = new ResourceEntity();

        result.setService(HzhrTypeUtil.string2string(in.getService()));
        result.setVersion(HzhrTypeUtil.string2string(in.getVersion()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        return result;
    }
    public ResourceEntity resourcePostModel2entity(ResourcePostModel in, ResourceEntity ori) {
        //未转换字段: createUserId createTime updateUserId isValid updateTime id state title 
        if (in == null) return null;
        ResourceEntity result = ori;

        result.setService(HzhrTypeUtil.string2string(in.getService()));
        result.setVersion(HzhrTypeUtil.string2string(in.getVersion()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        return result;
    }
    public List<ResourceEntity> resourcePostModelList2entityList(List<ResourcePostModel> in) {
        if (in == null) return null;
        List<ResourceEntity> result = new ArrayList<>();
        for (ResourcePostModel item : in) {
            result.add(resourcePostModel2entity(item));
        }
        return result;
    }
    public ResourcePostModel entity2resourcePostModel(ResourceEntity in) {
        //未转换字段: 
        if (in == null) return null;
        ResourcePostModel result = new ResourcePostModel();

        result.setService(HzhrTypeUtil.string2string(in.getService()));
        result.setVersion(HzhrTypeUtil.string2string(in.getVersion()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        return result;
    }
    public List<ResourcePostModel> entityList2resourcePostModelList(List<ResourceEntity> in) {
        if (in == null) return null;
        List<ResourcePostModel> result = new ArrayList<>();
        for (ResourceEntity item : in) {
            result.add(entity2resourcePostModel(item));
        }
        return result;
    }
    public ResourcePostModel ext2resourcePostModel(ResourceEntityExt in) {
        //未转换字段: 
        if (in == null) return null;
        ResourcePostModel result = new ResourcePostModel();

        result.setService(HzhrTypeUtil.string2string(in.getService()));
        result.setVersion(HzhrTypeUtil.string2string(in.getVersion()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        return result;
    }
    public List<ResourcePostModel> extList2resourcePostModelList(List<ResourceEntityExt> in) {
        if (in == null) return null;
        List<ResourcePostModel> result = new ArrayList<>();
        for (ResourceEntityExt item : in) {
            result.add(ext2resourcePostModel(item));
        }
        return result;
    }
    public ResourceEntity resourcePutModel2entity(ResourcePutModel in) {
        //未转换字段: createUserId createTime updateUserId isValid updateTime id state title 
        if (in == null) return null;
        ResourceEntity result = new ResourceEntity();

        result.setService(HzhrTypeUtil.string2string(in.getService()));
        result.setVersion(HzhrTypeUtil.string2string(in.getVersion()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        return result;
    }
    public ResourceEntity resourcePutModel2entity(ResourcePutModel in, ResourceEntity ori) {
        //未转换字段: createUserId createTime updateUserId isValid updateTime id state title 
        if (in == null) return null;
        ResourceEntity result = ori;

        result.setService(HzhrTypeUtil.string2string(in.getService()));
        result.setVersion(HzhrTypeUtil.string2string(in.getVersion()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        return result;
    }
    public List<ResourceEntity> resourcePutModelList2entityList(List<ResourcePutModel> in) {
        if (in == null) return null;
        List<ResourceEntity> result = new ArrayList<>();
        for (ResourcePutModel item : in) {
            result.add(resourcePutModel2entity(item));
        }
        return result;
    }
    public ResourcePutModel entity2resourcePutModel(ResourceEntity in) {
        //未转换字段: 
        if (in == null) return null;
        ResourcePutModel result = new ResourcePutModel();

        result.setService(HzhrTypeUtil.string2string(in.getService()));
        result.setVersion(HzhrTypeUtil.string2string(in.getVersion()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        return result;
    }
    public List<ResourcePutModel> entityList2resourcePutModelList(List<ResourceEntity> in) {
        if (in == null) return null;
        List<ResourcePutModel> result = new ArrayList<>();
        for (ResourceEntity item : in) {
            result.add(entity2resourcePutModel(item));
        }
        return result;
    }
    public ResourcePutModel ext2resourcePutModel(ResourceEntityExt in) {
        //未转换字段: 
        if (in == null) return null;
        ResourcePutModel result = new ResourcePutModel();

        result.setService(HzhrTypeUtil.string2string(in.getService()));
        result.setVersion(HzhrTypeUtil.string2string(in.getVersion()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        return result;
    }
    public List<ResourcePutModel> extList2resourcePutModelList(List<ResourceEntityExt> in) {
        if (in == null) return null;
        List<ResourcePutModel> result = new ArrayList<>();
        for (ResourceEntityExt item : in) {
            result.add(ext2resourcePutModel(item));
        }
        return result;
    }
    public ResourceCustomQueryModel resourceService_query2queryModel(Map<String, Object> query) {
        ResourceCustomQueryModel queryModel = new ResourceCustomQueryModel();

        Integer _equal_id = HzhrTypeUtil.object2integer(query.get("_equal_id"));
        if (_equal_id != null) {
            queryModel.setEqual_id(_equal_id);
         }

        String _equal_service = HzhrTypeUtil.object2string(query.get("_equal_service"));
        if (_equal_service != null) {
            queryModel.setEqual_service(_equal_service);
         }

        String _equal_version = HzhrTypeUtil.object2string(query.get("_equal_version"));
        if (_equal_version != null) {
            queryModel.setEqual_version(_equal_version);
         }

        String _equal_uri = HzhrTypeUtil.object2string(query.get("_equal_uri"));
        if (_equal_uri != null) {
            queryModel.setEqual_uri(_equal_uri);
         }

        String _like_uri = HzhrTypeUtil.object2string(query.get("_like_uri"));
        if (_like_uri != null) {
            queryModel.setLike_uri(_like_uri);
         }

        String _orderBy_uri = HzhrTypeUtil.object2string(query.get("_orderBy_uri"));
        if (_orderBy_uri != null) {
            queryModel.setOrderBy_uri(_orderBy_uri);
         }

        Integer _equal_userId = HzhrTypeUtil.object2integer(query.get("_equal_userId"));
        if (_equal_userId != null) {
            queryModel.setEqual_resourceInActionExtList_actionExt_actionInRoleExtList_roleExt_userInRoleExtList_userId(_equal_userId);
         }

        Boolean _show_info = HzhrTypeUtil.object2boolean(query.get("_show_info"));
        if (_show_info != null && _show_info) {
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setExt_resourceInActionExtList(true);
            queryModel.setShow14(true);
        }

        Integer page = HzhrTypeUtil.object2integer(query.get("_page"));
        Integer count = HzhrTypeUtil.object2integer(query.get("_count"));
        queryModel.setPage(page, count);

        return queryModel;
    }

}

